package com.mtung.cosumer.service;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.stereotype.Service;

/**
 * @author zhenguo.yao
 * @date 2020/12/11
 */
@Service
public class DiscoveryService {

    @NacosInjected
    private NamingService namingService;

    /**
     * 从nacos获取服务实例列表
     *
     * @param serviceName
     * @return
     * @throws NacosException
     */
    public Instance getInstance(String serviceName) throws NacosException {
        return namingService.selectOneHealthyInstance(serviceName);
    }

}
